﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NS_QuangCaoTiepThiBUS
{
    public class ChucVuBUS
    {
        public void Them(ChucVu cvDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            storeDB.ChucVus.InsertOnSubmit(cvDTO);

            storeDB.SubmitChanges();
        }

        public void Sua(ChucVu cvDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.ChucVus.Where(q => q.MaChucVu == cvDTO.MaChucVu).First();

            query.TenChucVu = cvDTO.TenChucVu;

            storeDB.SubmitChanges();
        }

        public void Xoa(ChucVu cvDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.ChucVus.Where(q => q.MaChucVu == cvDTO.MaChucVu).First();

            storeDB.ChucVus.DeleteOnSubmit(query);

            storeDB.SubmitChanges();
        }

        public IList<ChucVu> LayDanhSachChucVu()
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.ChucVus.ToList();

            return query;
        }

        public bool KiemTraTonTaiChucVu(ChucVu cvDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.ChucVus.Where(q => q.MaChucVu == cvDTO.MaChucVu).ToList();

            if (query.Count > 0)
            {
                return true;
            }

            return false;
        }
    }
}
